const fs = require('fs');
const path = require('path');

const baseDir = './img'; // 🔁 修改为你的文件夹路径
const serverUrl = 'http://localhost:3000/api/file/upload-folder';

let curl = `curl --location '${serverUrl}' \\\n`;

function walk(dir, relative = '') {
  const files = fs.readdirSync(dir);
  files.forEach(file => {
    const absolutePath = path.join(dir, file);
    const stat = fs.statSync(absolutePath);

    if (stat.isDirectory()) {
      walk(absolutePath, path.join(relative, file));
    } else {
      const relPath = path.join(relative, file).replace(/\\/g, '/'); // win兼容
      curl += `--form 'files=@"${absolutePath}";filename="${relPath}"' \\\n`;
    }
  });
}

walk(baseDir);

curl = curl.trim().replace(/\\\n$/, ''); // 去除最后一个反斜杠
fs.writeFileSync('upload_folder.curl.txt', curl, 'utf-8');
console.log('✅ 已生成 curl 命令文件：upload_folder.curl.txt');
